package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.StringUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserMsgSendPreDayDao;
import com.kly.user.db.entity.UserMsgSendPreDayEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.StringUtil;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/**
* User: linqu
* Date: 2023-10-17
* Time: 11:17:57.494
*/
@Slf4j
@Repository
public class UserMsgSendPreDayDaoImpl extends AbstractBaseMapper<UserMsgSendPreDayEntity> implements UserMsgSendPreDayDao {

    @Override
    public UserMsgSendPreDayEntity getUserMsgSendPreDay(Integer day, String fromUserCode, String toUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("day", day);
        params.put("fromUserCode", fromUserCode);
        params.put("toUserCode", toUserCode);
        return this.getSqlSession().selectOne(this.getStatement("getUserMsgSendPreDay"), params);
    }

    @Override
    public List<UserMsgSendPreDayEntity> listUserMsgToday(String fromUserCode, String toUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        if (StringUtils.isEmpty(fromUserCode)) {
            params.put("fromUserCode", fromUserCode);
        }
        if (StringUtils.isEmpty(toUserCode)) {
            params.put("toUserCode", toUserCode);
        }
        return this.getSqlSession().selectList(this.getStatement("listUserMsgToday"), params);
    }

    @Override
    public int updateReplied(String fromUserCode, String toUserCode) {
        try {
            final HashMap<String, Object> params = Maps.newHashMap();
            if (StringUtils.isNotEmpty(fromUserCode)) {
                params.put("fromUserCode", fromUserCode);
            }
            if (StringUtils.isNotEmpty(toUserCode)) {
                params.put("toUserCode", toUserCode);
            }
            return this.getSqlSession().update(this.getStatement("updateReplied"), params);
        } catch (Exception e) {
            log.error("updateRepliedError", e);
        }
        return 0;
    }
}